/** 
 * <p>Original Author:  jessefreeman</p>
 * <p>Class File: PaginationHelper.as</p>
 * 
 * <p>Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:</p>
 * 
 * <p>The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.</p>
 * 
 * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.</p>
 * 
 * <p>Licensed under The MIT License</p>
 * <p>Redistributions of files must retain the above copyright notice.</p>
 *
 * <p>Revisions<br/> 
 * 	0.1  Initial version Dec 26, 2008</p>
 *
 */

package camo.controllers.helpers
{
	
	public class PaginationHelper
	{
		public static const BEGINNING:String = "beginning";
		public static const MIDDLE:String = "middle";
		public static const END:String = "end";
		public static const NO_PAGES:String = "N/A";
		
		protected var _currentID:Number = -1;
		protected var _total:Number;
		protected var _loop:Boolean;
		
		/**
		 * 
		 * @param target
		 * 
		 */		
		public function PaginationHelper(totalPages:Number = 0, loop:Boolean = false)
		{
			_total = totalPages;
			_loop = loop;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		protected function get nextID():Number{
			var tempID:Number = _currentID + 1;
			
			_currentID = (tempID > (total)) ? ((_loop) ? 0 : total) : tempID;
			
			return _currentID;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		protected function get prevID():Number{
			var tempID:Number = _currentID - 1;
			
			_currentID = (tempID < 0) ? ((_loop) ? total : 0) : tempID;
			
			return _currentID;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function get total():Number{
			return _total;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function set total(value:Number):void{
			_total = value;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function get position():String{
			var tempPosition:String = "";
			if(_total == 0){
				tempPosition = NO_PAGES;
			}else{
				if(_currentID == 0){
					tempPosition = BEGINNING;
				}else if(_currentID == total){
					tempPosition = END;
				}else if(_currentID < 0){
					tempPosition = NO_PAGES;
				}else{
					tempPosition = MIDDLE;
				}
			}
			return tempPosition;
		}
		
		/**
		 * 
		 * 
		 */		
		public function get currentID():Number{
			return _currentID;
		}
		
		/**
		 * 
		 * 
		 */		
		public function set currentID(value:Number):void{
			_currentID = value;
		}
		
		/**
		 * 
		 * 
		 */		
		public function next():Number{
			return (_total) ? nextID : _currentID;
		}
		
		/**
		 * 
		 * 
		 */		
		public function previous():Number{
			return (_total) ? prevID : _currentID;
		}
		
	}
}